{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "6b299ee9",
   "metadata": {},
   "source": [
    "# Understanding the forecaster attributes\n",
    "\n",
    "During the process of creating and training a forecaster, the object stores a lot of information in its **attributes** that can be useful to the user. We will explore the main attributes included in a `ForecasterRecursive`, but this can be extrapolated to any of the skforecast forecasters."
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "d1ae70e1-1354-4aa6-9dc4-73d3c7b016c5",
   "metadata": {},
   "source": [
    "## Create and train a forecaster\n",
    "\n",
    "To be able to create and train a forecaster, at least `estimator` and `lags` and/or `window_features` must be specified."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "9c70f39b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Libraries\n",
    "# ==============================================================================\n",
    "from sklearn.ensemble import RandomForestRegressor\n",
    "from skforecast.datasets import load_demo_dataset\n",
    "from skforecast.preprocessing import RollingFeatures\n",
    "from skforecast.recursive import ForecasterRecursive"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "0c0024f6-5d9b-4e0d-a332-dfb71280d7e3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "    <style>\n",
       "        .container-e741560cc1cb4e1abcc079a6fb8eeb21 {\n",
       "            font-family: 'Arial', sans-serif;\n",
       "            font-size: 0.9em;\n",
       "            color: #333333;\n",
       "            border: 1px solid #ddd;\n",
       "            background-color: #f0f8ff;\n",
       "            padding: 5px 15px;\n",
       "            border-radius: 8px;\n",
       "            max-width: 600px;\n",
       "            #margin: auto;\n",
       "        }\n",
       "        .container-e741560cc1cb4e1abcc079a6fb8eeb21 h2 {\n",
       "            font-size: 1.5em;\n",
       "            color: #222222;\n",
       "            border-bottom: 2px solid #ddd;\n",
       "            padding-bottom: 5px;\n",
       "            margin-bottom: 15px;\n",
       "            margin-top: 5px;\n",
       "        }\n",
       "        .container-e741560cc1cb4e1abcc079a6fb8eeb21 details {\n",
       "            margin: 10px 0;\n",
       "        }\n",
       "        .container-e741560cc1cb4e1abcc079a6fb8eeb21 summary {\n",
       "            font-weight: bold;\n",
       "            font-size: 1.1em;\n",
       "            color: #000000;\n",
       "            cursor: pointer;\n",
       "            margin-bottom: 5px;\n",
       "            background-color: #b3dbfd;\n",
       "            padding: 5px;\n",
       "            border-radius: 5px;\n",
       "        }\n",
       "        .container-e741560cc1cb4e1abcc079a6fb8eeb21 summary:hover {\n",
       "            color: #000000;\n",
       "            background-color: #e0e0e0;\n",
       "        }\n",
       "        .container-e741560cc1cb4e1abcc079a6fb8eeb21 ul {\n",
       "            font-family: 'Courier New', monospace;\n",
       "            list-style-type: none;\n",
       "            padding-left: 20px;\n",
       "            margin: 10px 0;\n",
       "            line-height: normal;\n",
       "        }\n",
       "        .container-e741560cc1cb4e1abcc079a6fb8eeb21 li {\n",
       "            margin: 5px 0;\n",
       "            font-family: 'Courier New', monospace;\n",
       "        }\n",
       "        .container-e741560cc1cb4e1abcc079a6fb8eeb21 li strong {\n",
       "            font-weight: bold;\n",
       "            color: #444444;\n",
       "        }\n",
       "        .container-e741560cc1cb4e1abcc079a6fb8eeb21 li::before {\n",
       "            content: \"- \";\n",
       "            color: #666666;\n",
       "        }\n",
       "        .container-e741560cc1cb4e1abcc079a6fb8eeb21 a {\n",
       "            color: #001633;\n",
       "            text-decoration: none;\n",
       "        }\n",
       "        .container-e741560cc1cb4e1abcc079a6fb8eeb21 a:hover {\n",
       "            color: #359ccb; \n",
       "        }\n",
       "    </style>\n",
       "    \n",
       "        <div class=\"container-e741560cc1cb4e1abcc079a6fb8eeb21\">\n",
       "            <p style=\"font-size: 1.5em; font-weight: bold; margin-block-start: 0.83em; margin-block-end: 0.83em;\">ForecasterRecursive</p>\n",
       "            <details open>\n",
       "                <summary>General Information</summary>\n",
       "                <ul>\n",
       "                    <li><strong>Estimator:</strong> RandomForestRegressor</li>\n",
       "                    <li><strong>Lags:</strong> [1 2 3 4 5]</li>\n",
       "                    <li><strong>Window features:</strong> ['roll_mean_7']</li>\n",
       "                    <li><strong>Window size:</strong> 7</li>\n",
       "                    <li><strong>Series name:</strong> y</li>\n",
       "                    <li><strong>Exogenous included:</strong> False</li>\n",
       "                    <li><strong>Weight function included:</strong> False</li>\n",
       "                    <li><strong>Differentiation order:</strong> None</li>\n",
       "                    <li><strong>Creation date:</strong> 2025-11-26 14:31:51</li>\n",
       "                    <li><strong>Last fit date:</strong> 2025-11-26 14:31:51</li>\n",
       "                    <li><strong>Skforecast version:</strong> 0.19.0</li>\n",
       "                    <li><strong>Python version:</strong> 3.12.11</li>\n",
       "                    <li><strong>Forecaster id:</strong> None</li>\n",
       "                </ul>\n",
       "            </details>\n",
       "            <details>\n",
       "                <summary>Exogenous Variables</summary>\n",
       "                <ul>\n",
       "                    None\n",
       "                </ul>\n",
       "            </details>\n",
       "            <details>\n",
       "                <summary>Data Transformations</summary>\n",
       "                <ul>\n",
       "                    <li><strong>Transformer for y:</strong> None</li>\n",
       "                    <li><strong>Transformer for exog:</strong> None</li>\n",
       "                </ul>\n",
       "            </details>\n",
       "            <details>\n",
       "                <summary>Training Information</summary>\n",
       "                <ul>\n",
       "                    <li><strong>Training range:</strong> [Timestamp('1991-07-01 00:00:00'), Timestamp('2008-06-01 00:00:00')]</li>\n",
       "                    <li><strong>Training index type:</strong> DatetimeIndex</li>\n",
       "                    <li><strong>Training index frequency:</strong> <MonthBegin></li>\n",
       "                </ul>\n",
       "            </details>\n",
       "            <details>\n",
       "                <summary>Estimator Parameters</summary>\n",
       "                <ul>\n",
       "                    {'bootstrap': True, 'ccp_alpha': 0.0, 'criterion': 'squared_error', 'max_depth': None, 'max_features': 1.0, 'max_leaf_nodes': None, 'max_samples': None, 'min_impurity_decrease': 0.0, 'min_samples_leaf': 1, 'min_samples_split': 2, 'min_weight_fraction_leaf': 0.0, 'monotonic_cst': None, 'n_estimators': 100, 'n_jobs': None, 'oob_score': False, 'random_state': 123, 'verbose': 0, 'warm_start': False}\n",
       "                </ul>\n",
       "            </details>\n",
       "            <details>\n",
       "                <summary>Fit Kwargs</summary>\n",
       "                <ul>\n",
       "                    {}\n",
       "                </ul>\n",
       "            </details>\n",
       "            <p>\n",
       "                <a href=\"https://skforecast.org/0.19.0/api/forecasterrecursive.html\">&#128712 <strong>API Reference</strong></a>\n",
       "                &nbsp;&nbsp;\n",
       "                <a href=\"https://skforecast.org/0.19.0/user_guides/autoregressive-forecaster.html\">&#128462 <strong>User Guide</strong></a>\n",
       "            </p>\n",
       "        </div>\n",
       "        "
      ],
      "text/plain": [
       "=================== \n",
       "ForecasterRecursive \n",
       "=================== \n",
       "Estimator: RandomForestRegressor \n",
       "Lags: [1 2 3 4 5] \n",
       "Window features: ['roll_mean_7'] \n",
       "Window size: 7 \n",
       "Series name: y \n",
       "Exogenous included: False \n",
       "Exogenous names: None \n",
       "Transformer for y: None \n",
       "Transformer for exog: None \n",
       "Weight function included: False \n",
       "Differentiation order: None \n",
       "Training range: [Timestamp('1991-07-01 00:00:00'), Timestamp('2008-06-01 00:00:00')] \n",
       "Training index type: DatetimeIndex \n",
       "Training index frequency: <MonthBegin> \n",
       "Estimator parameters: \n",
       "    {'bootstrap': True, 'ccp_alpha': 0.0, 'criterion': 'squared_error', 'max_depth':\n",
       "    None, 'max_features': 1.0, 'max_leaf_nodes': None, 'max_samples': None,\n",
       "    'min_impurity_decrease': 0.0, 'min_samples_leaf': 1, 'min_samples_split': 2,\n",
       "    'min_weight_fraction_leaf': 0.0, 'monotonic_cst': None, 'n_estimators': 100,\n",
       "    'n_jobs': None, 'oob_score': False, 'random_state': 123, 'verbose': 0,\n",
       "    'warm_start': False} \n",
       "fit_kwargs: {} \n",
       "Creation date: 2025-11-26 14:31:51 \n",
       "Last fit date: 2025-11-26 14:31:51 \n",
       "Skforecast version: 0.19.0 \n",
       "Python version: 3.12.11 \n",
       "Forecaster id: None "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Download data\n",
    "# ==============================================================================\n",
    "y = load_demo_dataset()\n",
    "\n",
    "# Create and fit forecaster\n",
    "# ==============================================================================\n",
    "forecaster = ForecasterRecursive(\n",
    "                 estimator       = RandomForestRegressor(random_state=123),\n",
    "                 lags            = 5,\n",
    "                 window_features = RollingFeatures(stats=['mean'], window_sizes=[7])\n",
    "             )\n",
    "\n",
    "forecaster.fit(y=y)\n",
    "forecaster"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "b722e50e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "estimator\n",
      "transformer_y\n",
      "transformer_exog\n",
      "weight_func\n",
      "source_code_weight_func\n",
      "differentiation\n",
      "differentiation_max\n",
      "differentiator\n",
      "last_window_\n",
      "index_type_\n",
      "index_freq_\n",
      "training_range_\n",
      "series_name_in_\n",
      "exog_in_\n",
      "exog_names_in_\n",
      "exog_type_in_\n",
      "exog_dtypes_in_\n",
      "exog_dtypes_out_\n",
      "X_train_window_features_names_out_\n",
      "X_train_exog_names_out_\n",
      "X_train_features_names_out_\n",
      "in_sample_residuals_\n",
      "out_sample_residuals_\n",
      "in_sample_residuals_by_bin_\n",
      "out_sample_residuals_by_bin_\n",
      "creation_date\n",
      "is_fitted\n",
      "fit_date\n",
      "skforecast_version\n",
      "python_version\n",
      "forecaster_id\n",
      "_probabilistic_mode\n",
      "lags\n",
      "lags_names\n",
      "max_lag\n",
      "window_features\n",
      "window_features_names\n",
      "max_size_window_features\n",
      "window_size\n",
      "window_features_class_names\n",
      "fit_kwargs\n",
      "binner_kwargs\n",
      "binner\n",
      "binner_intervals_\n",
      "__skforecast_tags__\n"
     ]
    }
   ],
   "source": [
    "# List of attributes\n",
    "# ==============================================================================\n",
    "for attribute, value in forecaster.__dict__.items():\n",
    "    print(attribute)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "b949acd1",
   "metadata": {},
   "source": [
    "## Estimator\n",
    "\n",
    "Skforecast is a Python library that facilitates using `scikit-learn` estimators as multi-step forecasters and also works with any estimator compatible with the scikit-learn API. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "e5596357",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>#sk-container-id-1 {\n",
       "  /* Definition of color scheme common for light and dark mode */\n",
       "  --sklearn-color-text: #000;\n",
       "  --sklearn-color-text-muted: #666;\n",
       "  --sklearn-color-line: gray;\n",
       "  /* Definition of color scheme for unfitted estimators */\n",
       "  --sklearn-color-unfitted-level-0: #fff5e6;\n",
       "  --sklearn-color-unfitted-level-1: #f6e4d2;\n",
       "  --sklearn-color-unfitted-level-2: #ffe0b3;\n",
       "  --sklearn-color-unfitted-level-3: chocolate;\n",
       "  /* Definition of color scheme for fitted estimators */\n",
       "  --sklearn-color-fitted-level-0: #f0f8ff;\n",
       "  --sklearn-color-fitted-level-1: #d4ebff;\n",
       "  --sklearn-color-fitted-level-2: #b3dbfd;\n",
       "  --sklearn-color-fitted-level-3: cornflowerblue;\n",
       "\n",
       "  /* Specific color for light theme */\n",
       "  --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",
       "  --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, white)));\n",
       "  --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",
       "  --sklearn-color-icon: #696969;\n",
       "\n",
       "  @media (prefers-color-scheme: dark) {\n",
       "    /* Redefinition of color scheme for dark theme */\n",
       "    --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",
       "    --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, #111)));\n",
       "    --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",
       "    --sklearn-color-icon: #878787;\n",
       "  }\n",
       "}\n",
       "\n",
       "#sk-container-id-1 {\n",
       "  color: var(--sklearn-color-text);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 pre {\n",
       "  padding: 0;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 input.sk-hidden--visually {\n",
       "  border: 0;\n",
       "  clip: rect(1px 1px 1px 1px);\n",
       "  clip: rect(1px, 1px, 1px, 1px);\n",
       "  height: 1px;\n",
       "  margin: -1px;\n",
       "  overflow: hidden;\n",
       "  padding: 0;\n",
       "  position: absolute;\n",
       "  width: 1px;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-dashed-wrapped {\n",
       "  border: 1px dashed var(--sklearn-color-line);\n",
       "  margin: 0 0.4em 0.5em 0.4em;\n",
       "  box-sizing: border-box;\n",
       "  padding-bottom: 0.4em;\n",
       "  background-color: var(--sklearn-color-background);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-container {\n",
       "  /* jupyter's `normalize.less` sets `[hidden] { display: none; }`\n",
       "     but bootstrap.min.css set `[hidden] { display: none !important; }`\n",
       "     so we also need the `!important` here to be able to override the\n",
       "     default hidden behavior on the sphinx rendered scikit-learn.org.\n",
       "     See: https://github.com/scikit-learn/scikit-learn/issues/21755 */\n",
       "  display: inline-block !important;\n",
       "  position: relative;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-text-repr-fallback {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       "div.sk-parallel-item,\n",
       "div.sk-serial,\n",
       "div.sk-item {\n",
       "  /* draw centered vertical line to link estimators */\n",
       "  background-image: linear-gradient(var(--sklearn-color-text-on-default-background), var(--sklearn-color-text-on-default-background));\n",
       "  background-size: 2px 100%;\n",
       "  background-repeat: no-repeat;\n",
       "  background-position: center center;\n",
       "}\n",
       "\n",
       "/* Parallel-specific style estimator block */\n",
       "\n",
       "#sk-container-id-1 div.sk-parallel-item::after {\n",
       "  content: \"\";\n",
       "  width: 100%;\n",
       "  border-bottom: 2px solid var(--sklearn-color-text-on-default-background);\n",
       "  flex-grow: 1;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-parallel {\n",
       "  display: flex;\n",
       "  align-items: stretch;\n",
       "  justify-content: center;\n",
       "  background-color: var(--sklearn-color-background);\n",
       "  position: relative;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-parallel-item {\n",
       "  display: flex;\n",
       "  flex-direction: column;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-parallel-item:first-child::after {\n",
       "  align-self: flex-end;\n",
       "  width: 50%;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-parallel-item:last-child::after {\n",
       "  align-self: flex-start;\n",
       "  width: 50%;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-parallel-item:only-child::after {\n",
       "  width: 0;\n",
       "}\n",
       "\n",
       "/* Serial-specific style estimator block */\n",
       "\n",
       "#sk-container-id-1 div.sk-serial {\n",
       "  display: flex;\n",
       "  flex-direction: column;\n",
       "  align-items: center;\n",
       "  background-color: var(--sklearn-color-background);\n",
       "  padding-right: 1em;\n",
       "  padding-left: 1em;\n",
       "}\n",
       "\n",
       "\n",
       "/* Toggleable style: style used for estimator/Pipeline/ColumnTransformer box that is\n",
       "clickable and can be expanded/collapsed.\n",
       "- Pipeline and ColumnTransformer use this feature and define the default style\n",
       "- Estimators will overwrite some part of the style using the `sk-estimator` class\n",
       "*/\n",
       "\n",
       "/* Pipeline and ColumnTransformer style (default) */\n",
       "\n",
       "#sk-container-id-1 div.sk-toggleable {\n",
       "  /* Default theme specific background. It is overwritten whether we have a\n",
       "  specific estimator or a Pipeline/ColumnTransformer */\n",
       "  background-color: var(--sklearn-color-background);\n",
       "}\n",
       "\n",
       "/* Toggleable label */\n",
       "#sk-container-id-1 label.sk-toggleable__label {\n",
       "  cursor: pointer;\n",
       "  display: flex;\n",
       "  width: 100%;\n",
       "  margin-bottom: 0;\n",
       "  padding: 0.5em;\n",
       "  box-sizing: border-box;\n",
       "  text-align: center;\n",
       "  align-items: start;\n",
       "  justify-content: space-between;\n",
       "  gap: 0.5em;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 label.sk-toggleable__label .caption {\n",
       "  font-size: 0.6rem;\n",
       "  font-weight: lighter;\n",
       "  color: var(--sklearn-color-text-muted);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 label.sk-toggleable__label-arrow:before {\n",
       "  /* Arrow on the left of the label */\n",
       "  content: \"▸\";\n",
       "  float: left;\n",
       "  margin-right: 0.25em;\n",
       "  color: var(--sklearn-color-icon);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {\n",
       "  color: var(--sklearn-color-text);\n",
       "}\n",
       "\n",
       "/* Toggleable content - dropdown */\n",
       "\n",
       "#sk-container-id-1 div.sk-toggleable__content {\n",
       "  max-height: 0;\n",
       "  max-width: 0;\n",
       "  overflow: hidden;\n",
       "  text-align: left;\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-0);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-toggleable__content.fitted {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-0);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-toggleable__content pre {\n",
       "  margin: 0.2em;\n",
       "  border-radius: 0.25em;\n",
       "  color: var(--sklearn-color-text);\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-0);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-toggleable__content.fitted pre {\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-0);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {\n",
       "  /* Expand drop-down */\n",
       "  max-height: 200px;\n",
       "  max-width: 100%;\n",
       "  overflow: auto;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {\n",
       "  content: \"▾\";\n",
       "}\n",
       "\n",
       "/* Pipeline/ColumnTransformer-specific style */\n",
       "\n",
       "#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
       "  color: var(--sklearn-color-text);\n",
       "  background-color: var(--sklearn-color-unfitted-level-2);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
       "  background-color: var(--sklearn-color-fitted-level-2);\n",
       "}\n",
       "\n",
       "/* Estimator-specific style */\n",
       "\n",
       "/* Colorize estimator box */\n",
       "#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-2);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-2);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-label label.sk-toggleable__label,\n",
       "#sk-container-id-1 div.sk-label label {\n",
       "  /* The background is the default theme color */\n",
       "  color: var(--sklearn-color-text-on-default-background);\n",
       "}\n",
       "\n",
       "/* On hover, darken the color of the background */\n",
       "#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {\n",
       "  color: var(--sklearn-color-text);\n",
       "  background-color: var(--sklearn-color-unfitted-level-2);\n",
       "}\n",
       "\n",
       "/* Label box, darken color on hover, fitted */\n",
       "#sk-container-id-1 div.sk-label.fitted:hover label.sk-toggleable__label.fitted {\n",
       "  color: var(--sklearn-color-text);\n",
       "  background-color: var(--sklearn-color-fitted-level-2);\n",
       "}\n",
       "\n",
       "/* Estimator label */\n",
       "\n",
       "#sk-container-id-1 div.sk-label label {\n",
       "  font-family: monospace;\n",
       "  font-weight: bold;\n",
       "  display: inline-block;\n",
       "  line-height: 1.2em;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-label-container {\n",
       "  text-align: center;\n",
       "}\n",
       "\n",
       "/* Estimator-specific */\n",
       "#sk-container-id-1 div.sk-estimator {\n",
       "  font-family: monospace;\n",
       "  border: 1px dotted var(--sklearn-color-border-box);\n",
       "  border-radius: 0.25em;\n",
       "  box-sizing: border-box;\n",
       "  margin-bottom: 0.5em;\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-0);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-estimator.fitted {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-0);\n",
       "}\n",
       "\n",
       "/* on hover */\n",
       "#sk-container-id-1 div.sk-estimator:hover {\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-2);\n",
       "}\n",
       "\n",
       "#sk-container-id-1 div.sk-estimator.fitted:hover {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-2);\n",
       "}\n",
       "\n",
       "/* Specification for estimator info (e.g. \"i\" and \"?\") */\n",
       "\n",
       "/* Common style for \"i\" and \"?\" */\n",
       "\n",
       ".sk-estimator-doc-link,\n",
       "a:link.sk-estimator-doc-link,\n",
       "a:visited.sk-estimator-doc-link {\n",
       "  float: right;\n",
       "  font-size: smaller;\n",
       "  line-height: 1em;\n",
       "  font-family: monospace;\n",
       "  background-color: var(--sklearn-color-background);\n",
       "  border-radius: 1em;\n",
       "  height: 1em;\n",
       "  width: 1em;\n",
       "  text-decoration: none !important;\n",
       "  margin-left: 0.5em;\n",
       "  text-align: center;\n",
       "  /* unfitted */\n",
       "  border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
       "  color: var(--sklearn-color-unfitted-level-1);\n",
       "}\n",
       "\n",
       ".sk-estimator-doc-link.fitted,\n",
       "a:link.sk-estimator-doc-link.fitted,\n",
       "a:visited.sk-estimator-doc-link.fitted {\n",
       "  /* fitted */\n",
       "  border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
       "  color: var(--sklearn-color-fitted-level-1);\n",
       "}\n",
       "\n",
       "/* On hover */\n",
       "div.sk-estimator:hover .sk-estimator-doc-link:hover,\n",
       ".sk-estimator-doc-link:hover,\n",
       "div.sk-label-container:hover .sk-estimator-doc-link:hover,\n",
       ".sk-estimator-doc-link:hover {\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-3);\n",
       "  color: var(--sklearn-color-background);\n",
       "  text-decoration: none;\n",
       "}\n",
       "\n",
       "div.sk-estimator.fitted:hover .sk-estimator-doc-link.fitted:hover,\n",
       ".sk-estimator-doc-link.fitted:hover,\n",
       "div.sk-label-container:hover .sk-estimator-doc-link.fitted:hover,\n",
       ".sk-estimator-doc-link.fitted:hover {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-3);\n",
       "  color: var(--sklearn-color-background);\n",
       "  text-decoration: none;\n",
       "}\n",
       "\n",
       "/* Span, style for the box shown on hovering the info icon */\n",
       ".sk-estimator-doc-link span {\n",
       "  display: none;\n",
       "  z-index: 9999;\n",
       "  position: relative;\n",
       "  font-weight: normal;\n",
       "  right: .2ex;\n",
       "  padding: .5ex;\n",
       "  margin: .5ex;\n",
       "  width: min-content;\n",
       "  min-width: 20ex;\n",
       "  max-width: 50ex;\n",
       "  color: var(--sklearn-color-text);\n",
       "  box-shadow: 2pt 2pt 4pt #999;\n",
       "  /* unfitted */\n",
       "  background: var(--sklearn-color-unfitted-level-0);\n",
       "  border: .5pt solid var(--sklearn-color-unfitted-level-3);\n",
       "}\n",
       "\n",
       ".sk-estimator-doc-link.fitted span {\n",
       "  /* fitted */\n",
       "  background: var(--sklearn-color-fitted-level-0);\n",
       "  border: var(--sklearn-color-fitted-level-3);\n",
       "}\n",
       "\n",
       ".sk-estimator-doc-link:hover span {\n",
       "  display: block;\n",
       "}\n",
       "\n",
       "/* \"?\"-specific style due to the `<a>` HTML tag */\n",
       "\n",
       "#sk-container-id-1 a.estimator_doc_link {\n",
       "  float: right;\n",
       "  font-size: 1rem;\n",
       "  line-height: 1em;\n",
       "  font-family: monospace;\n",
       "  background-color: var(--sklearn-color-background);\n",
       "  border-radius: 1rem;\n",
       "  height: 1rem;\n",
       "  width: 1rem;\n",
       "  text-decoration: none;\n",
       "  /* unfitted */\n",
       "  color: var(--sklearn-color-unfitted-level-1);\n",
       "  border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 a.estimator_doc_link.fitted {\n",
       "  /* fitted */\n",
       "  border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
       "  color: var(--sklearn-color-fitted-level-1);\n",
       "}\n",
       "\n",
       "/* On hover */\n",
       "#sk-container-id-1 a.estimator_doc_link:hover {\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-3);\n",
       "  color: var(--sklearn-color-background);\n",
       "  text-decoration: none;\n",
       "}\n",
       "\n",
       "#sk-container-id-1 a.estimator_doc_link.fitted:hover {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-3);\n",
       "}\n",
       "</style><div id=\"sk-container-id-1\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>RandomForestRegressor(random_state=123)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator fitted sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-1\" type=\"checkbox\" checked><label for=\"sk-estimator-id-1\" class=\"sk-toggleable__label fitted sk-toggleable__label-arrow\"><div><div>RandomForestRegressor</div></div><div><a class=\"sk-estimator-doc-link fitted\" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.6/modules/generated/sklearn.ensemble.RandomForestRegressor.html\">?<span>Documentation for RandomForestRegressor</span></a><span class=\"sk-estimator-doc-link fitted\">i<span>Fitted</span></span></div></label><div class=\"sk-toggleable__content fitted\"><pre>RandomForestRegressor(random_state=123)</pre></div> </div></div></div></div>"
      ],
      "text/plain": [
       "RandomForestRegressor(random_state=123)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Forecaster estimator\n",
    "# ==============================================================================\n",
    "forecaster.estimator"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "9352f530",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'bootstrap': True,\n",
       " 'ccp_alpha': 0.0,\n",
       " 'criterion': 'squared_error',\n",
       " 'max_depth': None,\n",
       " 'max_features': 1.0,\n",
       " 'max_leaf_nodes': None,\n",
       " 'max_samples': None,\n",
       " 'min_impurity_decrease': 0.0,\n",
       " 'min_samples_leaf': 1,\n",
       " 'min_samples_split': 2,\n",
       " 'min_weight_fraction_leaf': 0.0,\n",
       " 'monotonic_cst': None,\n",
       " 'n_estimators': 100,\n",
       " 'n_jobs': None,\n",
       " 'oob_score': False,\n",
       " 'random_state': 123,\n",
       " 'verbose': 0,\n",
       " 'warm_start': False}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Show estimator parameters\n",
    "# ==============================================================================\n",
    "forecaster.estimator.get_params(deep=True)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "1c3dbe14",
   "metadata": {},
   "source": [
    "<div class=\"admonition note\" name=\"html-admonition\" style=\"background: rgba(0,184,212,.1); padding-top: 0px; padding-bottom: 6px; border-radius: 8px; border-left: 8px solid #00b8d4; border-color: #00b8d4; padding-left: 10px; padding-right: 10px;\">\n",
    "\n",
    "<p class=\"title\">\n",
    "    <i style=\"font-size: 18px; color:#00b8d4;\"></i>\n",
    "    <b style=\"color: #00b8d4;\">&#9998 Note</b>\n",
    "</p>\n",
    "\n",
    "In the forecasters that follows a <a href=\"../user_guides/direct-multi-step-forecasting.html\">Direct Strategy</a> (<a href=\"../api/forecasterdirect.html\"><code>ForecasterDirect</code></a> and <a href=\"../api/forecasterdirectmultivariate.html\"><code>ForecasterDirectMultiVariate</code></a>), one instance of the estimator is trained for each step. All of them are stored in <code>self.estimators_</code>\n",
    "\n",
    "</div>"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "ede0528f",
   "metadata": {},
   "source": [
    "## Lags\n",
    "\n",
    "Lags used as predictors. Index starts at 1, so lag 1 is equal to t-1."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "b71c8d05",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 3, 4, 5])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Forecaster lags\n",
    "# ==============================================================================\n",
    "forecaster.lags"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "73b3bfd5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Lags names :  ['lag_1', 'lag_2', 'lag_3', 'lag_4', 'lag_5']\n",
      "Max lag    :  5\n"
     ]
    }
   ],
   "source": [
    "# Lags information\n",
    "# ==============================================================================\n",
    "print(\"Lags names : \", forecaster.lags_names)\n",
    "print(\"Max lag    : \", forecaster.max_lag)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3018c83e",
   "metadata": {},
   "source": [
    "## Window features\n",
    "\n",
    "When forecasting time series data, it may be useful to consider additional characteristics beyond just the lagged values. For example, the moving average of the previous *n* values may help to capture the trend in the series. The `window_features` argument allows the inclusion of additional predictors created with the previous values of the series."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "d0be7ebb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[RollingFeatures(\n",
       "     stats           = ['mean'],\n",
       "     window_sizes    = [7],\n",
       "     Max window size = 7,\n",
       "     min_periods     = [7],\n",
       "     features_names  = ['roll_mean_7'],\n",
       "     fillna          = None\n",
       "     kwargs_stats    = {'ewm': {'alpha': 0.3}},\n",
       " )]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Forecaster window features\n",
    "# ==============================================================================\n",
    "forecaster.window_features"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "36c65e35",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Window features names   :  ['roll_mean_7']\n",
      "Max window size wf      :  7\n",
      "Window features classes :  ['RollingFeatures']\n"
     ]
    }
   ],
   "source": [
    "# Window features information\n",
    "# ==============================================================================\n",
    "print(\"Window features names   : \", forecaster.window_features_names)\n",
    "print(\"Max window size wf      : \", forecaster.max_size_window_features)\n",
    "print(\"Window features classes : \", forecaster.window_features_class_names)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "a13614ed",
   "metadata": {},
   "source": [
    "## Window size\n",
    "\n",
    "The size of the data window needed to create the predictors. It is the maximum between the maximum lag and the maximum window required by the window features."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "28bd1661",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Max lag            :  5\n",
      "Max window size wf :  7\n",
      "Window size        :  7\n"
     ]
    }
   ],
   "source": [
    "# Forecaster window size\n",
    "# ==============================================================================\n",
    "print(\"Max lag            : \", forecaster.max_lag)\n",
    "print(\"Max window size wf : \", forecaster.max_size_window_features)\n",
    "print(\"Window size        : \", forecaster.window_size)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "7b01accc",
   "metadata": {},
   "source": [
    "## Last window\n",
    "\n",
    "Last window the forecaster has seen during training. It stores the values needed to predict the next `step` immediately after the training data."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "fa178d33",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>y</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>datetime</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2007-12-01</th>\n",
       "      <td>1.176589</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2008-01-01</th>\n",
       "      <td>1.219941</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2008-02-01</th>\n",
       "      <td>0.761822</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2008-03-01</th>\n",
       "      <td>0.649435</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2008-04-01</th>\n",
       "      <td>0.827887</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2008-05-01</th>\n",
       "      <td>0.816255</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2008-06-01</th>\n",
       "      <td>0.762137</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   y\n",
       "datetime            \n",
       "2007-12-01  1.176589\n",
       "2008-01-01  1.219941\n",
       "2008-02-01  0.761822\n",
       "2008-03-01  0.649435\n",
       "2008-04-01  0.827887\n",
       "2008-05-01  0.816255\n",
       "2008-06-01  0.762137"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Forecaster last window\n",
    "# ==============================================================================\n",
    "forecaster.last_window_"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "2f0d6a64",
   "metadata": {},
   "source": [
    "<div class=\"admonition note\" name=\"html-admonition\" style=\"background: rgba(0,191,191,.1); padding-top: 0px; padding-bottom: 6px; border-radius: 8px; border-left: 8px solid #00bfa5; border-color: #00bfa5; padding-left: 10px; padding-right: 10px;\">\n",
    "\n",
    "<p class=\"title\">\n",
    "    <i style=\"font-size: 18px; color:#00bfa5;\"></i>\n",
    "    <b style=\"color: #00bfa5;\">&#128161 Tip</b>\n",
    "</p>\n",
    "\n",
    "\n",
    "Learn how to get your forecasters into production and get the most out of them with <code>last_window</code>. <a href=\"../user_guides/forecaster-in-production.html\">Using forecasting models in production</a>.\n",
    "\n",
    "</div>"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "3cc973da",
   "metadata": {},
   "source": [
    "## In-sample residuals\n",
    "\n",
    "The residuals of the in-sample predictions. This is the difference between the true values and the predictions made by the forecaster on the training data.\n",
    "\n",
    "In order to save conputational resources, the residuals are only stored if the user specifies `store_residuals=True` when training the forecaster. If the forecaster is already trained and the user wants to store the residuals, the method `set_in_sample_residuals()` can be used.\n",
    "\n",
    "If the forecaster includes a transformer, the residuals are stored in the transformed scale. "
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "c4098858",
   "metadata": {},
   "source": [
    "<div class=\"admonition note\" name=\"html-admonition\" style=\"background: rgba(0,184,212,.1); padding-top: 0px; padding-bottom: 6px; border-radius: 8px; border-left: 8px solid #00b8d4; border-color: #00b8d4; padding-left: 10px; padding-right: 10px;\">\n",
    "\n",
    "<p class=\"title\">\n",
    "    <i style=\"font-size: 18px; color:#00b8d4;\"></i>\n",
    "    <b style=\"color: #00b8d4;\">&#9998 Note</b>\n",
    "</p>\n",
    "\n",
    "In the forecasters that follows a <a href=\"../user_guides/direct-multi-step-forecasting.html\">Direct Strategy</a> (<a href=\"../api/forecasterdirect.html\"><code>ForecasterDirect</code></a> and <a href=\"../api/forecasterdirectmultivariate.html\"><code>ForecasterDirectMultiVariate</code></a>) and in the <a href=\"../user_guides/independent-multi-time-series-forecasting.html\">\n",
    "Global Forecasting Models: Independent multi-series forecasting</a> (<a href=\"../api/forecasterrecursivemultiseries.html\"><code>ForecasterRecursiveMultiSeries</code></a>) this parameter is a <code>dict</code> containing the residuals for each estimator/serie.\n",
    "\n",
    "</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "5d0f57f3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Length: 197\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([-0.13137208, -0.03279934, -0.00417238, -0.02469213,  0.00563615])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Forecaster in-sample residuals\n",
    "# ==============================================================================\n",
    "forecaster.fit(y=y, store_in_sample_residuals=True)\n",
    "\n",
    "print(\"Length:\", len(forecaster.in_sample_residuals_))\n",
    "forecaster.in_sample_residuals_[:5]"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "10f5a8f2",
   "metadata": {},
   "source": [
    "## Out-of-sample residuals\n",
    "\n",
    "Residuals from models predicting non training data. If `transformer_y` is not `None`, residuals are assumed to be in the transformed scale. Use `set_out_sample_residuals`  method to set values.\n",
    "\n",
    "As no values have been added, the parameter is `None`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "37a73add",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Forecaster out-of-sample residuals\n",
    "# ==============================================================================\n",
    "forecaster.out_sample_residuals_"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9b64d8e9",
   "metadata": {},
   "source": [
    "## Skforecast tags\n",
    "\n",
    "All Forecasters include the attribute `__skforecast_tags__` which provides metadata about the forecaster, such as its capabilities and limitations. This attribute can be useful for introspection and understanding the behavior of different forecasters."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "02a4a786",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'library': 'skforecast',\n",
       " 'forecaster_name': 'ForecasterRecursive',\n",
       " 'forecaster_task': 'regression',\n",
       " 'forecasting_scope': 'single-series',\n",
       " 'forecasting_strategy': 'recursive',\n",
       " 'index_types_supported': ['pandas.RangeIndex', 'pandas.DatetimeIndex'],\n",
       " 'requires_index_frequency': True,\n",
       " 'allowed_input_types_series': ['pandas.Series'],\n",
       " 'supports_exog': True,\n",
       " 'allowed_input_types_exog': ['pandas.Series', 'pandas.DataFrame'],\n",
       " 'handles_missing_values_series': False,\n",
       " 'handles_missing_values_exog': True,\n",
       " 'supports_lags': True,\n",
       " 'supports_window_features': True,\n",
       " 'supports_transformer_series': True,\n",
       " 'supports_transformer_exog': True,\n",
       " 'supports_weight_func': True,\n",
       " 'supports_differentiation': True,\n",
       " 'prediction_types': ['point',\n",
       "  'interval',\n",
       "  'bootstrapping',\n",
       "  'quantiles',\n",
       "  'distribution'],\n",
       " 'supports_probabilistic': True,\n",
       " 'probabilistic_methods': ['bootstrapping', 'conformal'],\n",
       " 'handles_binned_residuals': True}"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Forecaster tags\n",
    "# ==============================================================================\n",
    "forecaster.get_tags()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "skforecast_py12",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
